<!doctype html>
<html lang="zh-CN">
<head>
    <meta charset="utf-8">
    <meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
    <title>会员中心-修改登录密码</title>
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="author" content="夜读书">
    <meta name="description" content="夜读书中文网">
    <meta name="keywords" content="读书,阅读,小说,文学">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="{{ asset('/bootstrap-3.3.5-dist/css/bootstrap.min.css') }}">
    <link rel="stylesheet" href="{{ asset('/style/css/yds.css') }}">
    <link rel="stylesheet" href="{{ asset('/style/css/ucenter.css') }}">
    <script src="{{ asset('/scripts/jquery/jquery-1.11.3.min.js') }}"></script>
    <script src="{{ asset('/bootstrap-3.3.5-dist/js/bootstrap.min.js') }}"></script>
</head>
<body>
@include('books.partials.navtop')
@include('books.partials.nav')
<div id="yds_screen">
<div id="yds_content" class="clearfix">
@include('ucenter.partials.adminmenu')
  <div class="spaceList adminbody">
    <div class="adminhead">
        <h1>修改登录密码</h1>
    </div>
    <div class="admincontent mainform">
        <form name="form" class="form-horizontal" method="post" action="">
        <input type="hidden" name="_token" value="{{ csrf_token() }}" />              
        <table width="100%">
        <tbody>
        <tr>
        <td width="150"><span>旧的登录密码:</span></td>
        <td>
            <input class="form-control oldpwd" style="width:300px;" name="oldpwd" maxlength="128" value="" type="password"></input>
        </td>           
        </tr>
        <tr>
        <td><span>新密码:</span></td>
        <td>
            <input class="form-control newpwd" style="width:300px;" name="newpwd" maxlength="128" value="" type="password"></input>
        </td>
        </tr>
        <tr>
            <td><span>再次输入新密码:</span></td>        
        <td>
            <input class="form-control newpwd2" style="width:300px;" name="newpwd2" maxlength="128" value="" type="password"></input>
        </td>
        </tr>
        <tr>
            <th colspan="2"></th>
        </tr>
        <tr class="submit">
        <th></th>
        <td>
            <div class="bton"><span class="ms"></span><button type="button" id="savechpwd" class="btn btn-success">修改密码</button></div>
        </td>
        </tr>
        </tbody>
        </table>
        </form>
    </div>
  </div>
</div>
</div>
@include('books.partials.footer')

<script>
    $(document).ready(function(){
        $("#savechpwd").click(function (){
            if($(".oldpwd").val() == ""){
                $(".ms").html("<span class='msinfo'><font color='red'>请输入旧密码</font></span>");
                $(".oldpwd").focus();
                return false;  
            }else if($(".newpwd").val().trim() == ""){
                $(".ms").html("<span class='msinfo'><font color='red'>请输入新密码</font></span>");
                $(".newpwd").val("");
                $(".newpwd").focus();
                return false;
            }else if($(".newpwd").val().length < 6 || $(".newpwd").val().length > 16){
                $(".ms").html("<span class='msinfo'><font color='red'>密码必须为6到16位字符</font></span>");
                $(".newpwd").focus();
                return false;
            }else if($(".newpwd").val() != $(".newpwd2").val()){
                $(".ms").html("<span class='msinfo'><font color='red'>两次确认密码不相同</font></span>");
                $(".newpwd2").focus();
                return false;
            }else{
                ischeckchpwd();
            }            
        });

        function ischeckchpwd(){
            //检测密码是否正确
            $.ajax({
                type: 'post',   
                url: '{{url('u/admin/ischeckchpwd')}}',               
                dataType: 'text',
                data: $("form").serialize(),                
                success: function (msg) {
                    if (msg == "正确"){
                        //输入的旧密码正确
                        savechpwd();
                    }else{
                        //输入的旧密码错误
                        $(".ms").html("<span class='msinfo'><font color='red'>旧密码输入错误</font></span>");
                        $(".oldpwd").focus();
                        return false;                 
                    }
                }
            });
        }

        function savechpwd(){
            //保存会员修改的新密码
            $.ajax({
                type: 'post',   
                url: '{{url('u/admin/savechpwd')}}',               
                dataType: 'text', 
                data: $("form").serialize(),              
                success: function (msg) {
                    if (msg == "ok"){
                        //修改成功
                        $(".ms").html("<span class='msinfo'><font color='red'>密码修改成功!</font></span>");
                        return false; 
                    }
                }
            });
        }

    });

    
</script>

</body>
</html>
